package org.cheetah.core.endpoint.spi;

import org.cheetah.core.Service;
import org.cheetah.core.ServiceInvoker;
import org.cheetah.core.endpoint.EndpointProducer;
import org.cheetah.core.exchange.Exchange;

public class ServiceEndpointProducer implements EndpointProducer {
	private ServiceInvoker invoker;

	public ServiceEndpointProducer(String name) {
		invoker = Service.invoker(name);
		if (invoker == null) {
			throw new IllegalArgumentException("cannot find service " + name);
		}
	}

	public void send(Exchange exchange) throws Exception {
		exchange.setOut(invoker.deliver(exchange.getIn()));
	}
}
